﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Pahan.McuFusion.UI.Workspaces;

namespace Pahan.McuFusion.UI.Controls
{
    public partial class WorkspaceBox : UserControl
    {
        public WorkspaceBox()
        {
            InitializeComponent();
        }

        public Workspace Workspace
        {
            get
            {
                return workspace;
            }
            set
            {
                workspace = value;
                if (workspace == null)
                {
                    pEmpty.Visible = true;
                    scWorkspace.Visible = false;
                }
                else
                {
                    pEmpty.Visible = false;
                    scWorkspace.Visible = true;
                    FillWorkspaceInfo();
                }
                pgWorkspaceProperties.SelectedObject = 
                    workspace != null ? workspace.GetOptions() : null;
                pgWorkspaceProperties.ExpandAllGridItems();
            }
        }

        private void FillWorkspaceInfo()
        {
            dbDevice.SubTitle = String.Format("{0} {1}",
                workspace.DeviceInfo.Vendor,
                workspace.DeviceInfo.Model);
            dbDevice.Text = workspace.DeviceInfo.Description;

            dbProgrammer.SubTitle = workspace.ProgrammerInfo.Name;
            dbProgrammer.Text = workspace.ProgrammerInfo.Description;

            dbHardwareAdapter.SubTitle = workspace.HardwareAdapterInfo.Name;
            dbHardwareAdapter.Text = workspace.HardwareAdapterInfo.Description;

            dbHardwareInterface.SubTitle = workspace.HardwareInterfaceInfo.Name;
            dbHardwareInterface.Text = workspace.HardwareInterfaceInfo.Description;
        }

        private void pgWorkspaceProperties_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            workspace.SetModified();
        }

        private Workspace workspace;
    }
}
